package com.xiaoyushu.note.biz.consumer;

import com.xiaoyushu.note.biz.constants.MQConstants;
import com.xiaoyushu.note.biz.constants.RedisKeyConstants;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@RocketMQMessageListener(consumerGroup = "xiaoyushu_group_"+ MQConstants.TOPIC_DELAY_DELETE_NOTE_REDIS_CACHE,//Group
 topic = MQConstants.TOPIC_DELAY_DELETE_NOTE_REDIS_CACHE)//消费 主题Topic
public class DelayDeleteNoteRedisCacheConsumer implements RocketMQListener<String> {
    @Resource
    private RedisTemplate<String,Object> redisTemplate;

    /**
     * @param message
     */
    @Override
    public void onMessage(String message) {
        Long noteId=Long.valueOf( message);
        log.info("## 延迟删除笔记缓存, noteId: {}", noteId);
        //删除Redis 笔记缓存
        String noteRedisKey= RedisKeyConstants.buildNoteDetailKey(noteId);
        redisTemplate.delete(noteRedisKey);
    }
}
